#include <bits/stdc++.h>
using namespace std;

vector<int> p[5001];
vector<tuple<int, int, int>> ask[5001];
int n, m, k, cnt, dis[5001][2], ans[1000001];

void bfs(int start)
{
    queue<pair<int, int>> q;
    q.push({ start, 0 });
    dis[start][0] = 0;
    while (!q.empty()) {
        int u = q.front().first, dist = q.front().second;
        q.pop();
        for (int i = 0; i < p[u].size(); i++) {
            int v = p[u][i];
            if (dis[v][!(dist & 1)] > dis[u][dist & 1] + 1) {
                dis[v][!(dist & 1)] = dis[u][dist & 1] + 1;
                q.push({ v, dist + 1 });
            }
        }
    }
}

int read(){
    int x = 0;
    char c = getchar();
    while (c < '0' || c > '9') 
        c = getchar();
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    n = read(), m = read(), k = read();
    for (int i = 1; i <= m; i++) {
        int u, v;
        u = read(), v = read();
        p[u].push_back(v);
        p[v].push_back(u);
    }
    for (int i = 1; i <= k; i++) {
        int s, t, d;
        s = read(), t = read(), d = read();
        ask[s].push_back({ t, d, i });
    }
    for (int i = 1; i <= n; i++) {
        if (ask[i].empty())
            continue;
        memset(dis, 0x3f, sizeof(dis));
        bfs(i);
        for (int j = 0; j < ask[i].size(); j++) {
            int t = get<0>(ask[i][j]), d = get<1>(ask[i][j]), id = get<2>(ask[i][j]);
            if (dis[t][d & 1] <= d) 
                if (!(t == i && (d & 1) == 0 && p[i].empty())) 
                    ans[id] = 1;
        }
    }
    for (int i = 1; i <= k; i++)
        if (ans[i] == 1)
            puts("TAK");
        else
            puts("NIE");
    return 0;
}